package com.base.myproject.client.HR.recruitment;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseTreeStore;
import com.base.myproject.client.busi.BO.BaseObject;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.BaseResource;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.BaseTabPanel;
import com.base.myproject.client.ui.SignleFileUpload;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.celleditor.BaseComboBoxX;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.TreeModel;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.event.TreePanelEvent;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.CheckCascade;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel.CheckNodes;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * @author cxghiu410@gmail.com
 * @see com.base.myproject.client.ui.SignleFileUpload 简历库
 */
public class ResumeLibrary extends BaseJDBCPanel {
	String treeDepId = null; // 将当前树形结构中选中的部门id保存
	String treeDepName = null; // 将当前树形结构中选中的部门name保存
	TreePanel<TreeModel> treepanel = null;
	BaseComboBoxForm<BaseModelData> sectionCode = new BaseComboBoxForm<BaseModelData>(
			"id", "name", "SystemInfo",
			"where name is not null and id is not null", true);

	SignleFileUpload swfu; // 显示上传界面
	String resumeLibrary = "/resumeLibrary/"; // 文件默认存放的父路径

	Button search = new Button("查询");
	Button request = new Button("申请职位");

	Long recruitmentId = 0L; // 保存要关联的人力申请表ID

	String sql = "select * from hr_resumeLibrary where 1=1"; // 用于设置页面默认打开时使用的sql语句

	Dialog dialog = new Dialog(); // 弹出框，主要用于申请时让用户自己选择信息来源
	BaseComboBoxX box = new BaseComboBoxX("name", "dictionary",
			" where type = 'informationFrom'");// 信息来源的显示框

	public ResumeLibrary() {
		init();
	}

	/**
	 * @param sql
	 *            页面默认打开的sql语句 这个构造方法主要用于设置这个页面的sql，并让职位的名称为固定值(申请职位的名称)
	 */
	public ResumeLibrary(String sql, String name) {
		this.sql = sql;
		position.setValue(name);
		position.setEnabled(false);
		init();
	}

	public void init() {
		dialog.setHeading("请选择信息来源");
		dialog.add(box);
		dialog.setButtons(Dialog.OKCANCEL);
		dialog.getButtonById(Dialog.CANCEL)
		.setText("暂时不填写");
		dialog.setSize(200, 90);

		initWidget();
		registerMainStore(store);
		search.addListener(Events.OnClick, getListener());
		request.addListener(Events.OnClick, getListener());
	}

	public void initWidget() {
		HorizontalPanel hp = new HorizontalPanel();
		hp.setSpacing(5);

		VerticalPanel vp = new VerticalPanel();
		vp.setSpacing(5);
		FieldSet fs = new FieldSet();
		fs.setCheckboxToggle(true);
		fs.setExpanded(false);
		fs.setHeading("雇员查询");

		fs.add(createForm());
		HorizontalPanel s = new HorizontalPanel();
		s.add(search);
		s.add(request);
		fs.add(s);

		ContentPanel tree = new ContentPanel();
		tree.add(getTreePanel());
		tree.setHeading("选择部门");

		vp.add(fs);
		vp.add(getGrid());
		ContentPanel content = new ContentPanel();
		content.add(vp);
		content.setHeaderVisible(false);

		hp.add(tree);
		hp.add(content);
		add(hp);
		this.layout();
	}

	BaseTreeStore<TreeModel> treeStore = null;

	private TreePanel<TreeModel> getTreePanel() {
		if (treepanel == null) {
			initTreePanel();
		}
		return treepanel;
	}

	private BaseTreeStore<TreeModel> getTreeStore() {
		if (treeStore == null) {
			initTreeStore();
		}
		return treeStore;
	}

	private BaseTreeStore<TreeModel> initTreeStore() {
		StoreInfo info = new StoreInfo();
		String sql2 = "select icode,id,name from SystemInfo where id is not null order by id asc";
		info.setSql(sql2);
		info.setTreesortcolumn("id");
		info.setKeyname(new String[] { "icode" });
		info.setTablename("SystemInfo");
		treeStore = new BaseTreeStore<TreeModel>(info, false);
		treeStore.load();
		return treeStore;
	}

	private void initTreePanel() {
		treepanel = new TreePanel<TreeModel>(getTreeStore());
		Tools.setResize(treepanel, 0.18, 0.95);
		treepanel.setBorders(true);
		treepanel.setDisplayProperty("name");
		treepanel.setCheckStyle(CheckCascade.PARENTS);
		treepanel.setCheckNodes(CheckNodes.BOTH);
		treepanel.getStyle().setLeafIcon(
				AbstractImagePrototype
						.create(BaseResource.INSTANCE.tree_file()));
		treepanel.setCheckable(false);
		treepanel.setAutoLoad(true);
		treepanel.setCaching(true);
		treepanel.setBorders(false);

		treepanel.addListener(Events.OnClick,
				new Listener<TreePanelEvent<TreeModel>>() {
					public void handleEvent(TreePanelEvent<TreeModel> be) {
						if (be.getItem() != null) {
							String id = be.getItem().get("id").toString();
							treeDepId = id;
							treeDepName = be.getItem().get("name").toString();
							set_grid(id);
						}
					}
				});
	}

	private void set_grid(String id) {
		StoreInfo info2 = new StoreInfo();
		info2.setTablename("hr_resumeLibrary");
		info2.setKeyname(new String[] { "icode" });
		String where = "";

		if (id.length() < 5) {
			where = " and depCode like '" + id + "%25'";
		} else {
			where = " and depCode = '" + id + "'";
		}
		info2.setSql(sql + where);
		grid.getBg().getStore().setStoreinfo(info2);
		grid.getBg().getStore().reload();
		// grid.getView().refresh(true);
	}

	FormPanel form;
	TextField<String> position = new TextField<String>(); // 职位
	TextField<String> name = new TextField<String>(); // 申请人
	BaseComboBoxX education = new BaseComboBoxX("name", "dictionary",
			" where type = 'hr_education'");
	BaseComboBoxX experience = new BaseComboBoxX("name", "dictionary",
			" where type = 'experience'");
	TextField<String> skills = new TextField<String>(); // 技能
	NumberField salaryStart = new NumberField(); // 薪金要求
	NumberField salaryEnd = new NumberField(); // 薪金要求
	TextField<String> resumeNo = new TextField<String>(); // 简历编号

	private FormPanel createForm() {
		form = new FormPanel();

		TableLayout tl = new TableLayout(8);

		form.setWidth(913);
		form.setPadding(4);
		form.setBodyBorder(false);
		form.setHeaderVisible(false);
		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);

		form.add(new Label("职位名称:"), td);
		position.setWidth(127);
		form.add(position, td);

		form.add(new Label("申请人:"), td);
		name.setWidth(127);
		form.add(name, td);

		form.add(new Label("教育程度:"), td);
		education.setWidth(127);
		form.add(education, td);

		form.add(new Label("工作年限:"), td);
		experience.setWidth(127);
		form.add(experience, td);

		form.add(new Label("技能:"), td);
		skills.setWidth(127);
		form.add(skills, td);

		form.add(new Label("简历编号:"), td);
		resumeNo.setWidth(127);
		form.add(resumeNo, td);

		form.add(new Label("薪金从:"), td);
		salaryStart.setPropertyEditorType(Double.class);
		salaryStart.setWidth(127);
		form.add(salaryStart, td);

		form.add(new Label("到:"), td);
		salaryEnd.setPropertyEditorType(Double.class);
		salaryEnd.setWidth(127);
		form.add(salaryEnd, td);

		form.setLayout(tl);

		return form;
	}

	BaseStore<BusiObject> store = null;

	private BaseStore<BusiObject> getStore() {
		if (store == null) {
			createStore();
		}
		return store;
	}

	private BaseStore<BusiObject> createStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("uploadDate");
		type.getField("uploadDate").setType(Date.class);
		type.addField("resumeNo");
		type.getField("resumeNo").setType(String.class);
		type.addField("position");
		type.getField("position").setType(String.class);
		type.addField("depCode");
		type.getField("depCode").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);
		type.addField("education");
		type.getField("education").setType(String.class);
		type.addField("experience");
		type.getField("experience").setType(String.class);
		type.addField("salary");
		type.getField("salary").setType(Double.class);
		type.addField("skills");
		type.getField("skills").setType(String.class);
		type.addField("uploader");
		type.getField("uploader").setType(String.class);
		type.addField("uploadFile");
		type.getField("uploadFile").setType(String.class);
		type.addField("uploadFileName");
		type.getField("uploadFileName").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_resumeLibrary");
		info.setKeyname(new String[] { "icode" });
		info.setSql(sql);
		store = new BaseStore<BusiObject>(type, info);
		return store;
	}

	ModelType type = new ModelType();

	BaseGridPanel grid = null;

	private BaseGridPanel getGrid() {
		if (grid == null) {
			createGrid();
		}
		return grid;
	}

	CheckBoxSelectionModel cbs;

	/**
	 * 定义一个grid，用来显示是传的简历的数据，并通过实例化一个SignleFileUpload 对象来显示一个上传对话框。
	 * 
	 * @return grid 一个BaseGrid对象
	 */
	private BaseGridPanel createGrid() {
		cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		GridCellRenderer<ModelData> renderer = new GridCellRenderer<ModelData>() {
			public String render(ModelData model, String property,
					ColumnData d, int rowIndex, int colIndex,
					ListStore<ModelData> store, Grid<ModelData> grid) {
				if (model.get(property) != null
						&& model.get(property) instanceof ModelData) {
					return ((ModelData) model.get(property)).get("value");
				}
				return model.get(property);
			}
		};

		BaseComboBoxX education = new BaseComboBoxX("name", "dictionary",
				" where type = 'hr_education'");
		BaseComboBoxX experience = new BaseComboBoxX("name", "dictionary",
				" where type = 'experience'");
		BaseComboBoxX position = new BaseComboBoxX("position",
				"hr_recruitmentRequest",
				" where isThrough = 'true' and hirePeople is null");

		ColumnConfig C40 = new ColumnConfig("resumeNo", "简历编号", 80);
		columns.add(C40);

		ColumnConfig C3 = new ColumnConfig("depCode", "部门名称", 80);
		C3.setEditor(sectionCode.getCelEditor());
		C3.setRenderer(sectionCode);
		columns.add(C3);
		ColumnConfig C15 = new ColumnConfig("position", "申请职位名", 80);
		C15.setRenderer(renderer);
		C15.setEditor(position.getCellEditor());
		columns.add(C15);
		ColumnConfig C11 = new ColumnConfig("uploadFileName", "上传文件", 200);
		TextField<String> text4 = new TextField<String>();
		C11.setEditor(new CellEditor(text4));
		columns.add(C11);
		C11.setRenderer(new GridCellRenderer<ModelData>() {

			public Object render(ModelData model, String property,
					ColumnData config, int rowIndex, int colIndex,
					ListStore<ModelData> store, Grid<ModelData> grid) {
				if (model.get("uploadFile") == null) {
					return "<b><a style=\"color: #385F95; text-decoration: none;\" href=\""
							+ model.get("uploadFileName")
							+ "\" target=\"_blank\">"
							+ model.get("uploadFileName") + "</a>";
				} else {
					return "<b><a style=\"color: #385F95; text-decoration: none;\" href=\""
							+ model.get("uploadFile")
							+ "\" target=\"_blank\">"
							+ model.get("uploadFileName") + "</a>";
				}
			}

		});
		ColumnConfig C4 = new ColumnConfig("name", "姓名", 80);
		TextField<String> text = new TextField<String>();
		C4.setEditor(new CellEditor(text));
		columns.add(C4);

		ColumnConfig C5 = new ColumnConfig("education", "教育程度", 80);
		C5.setRenderer(renderer);
		C5.setEditor(education.getCellEditor());
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("experience", "工作年限", 80);
		C6.setRenderer(renderer);
		C6.setEditor(experience.getCellEditor());
		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("salary", "薪金要求", 80);
		NumberField number_data = new NumberField();
		number_data.setPropertyEditorType(Double.class);
		C7.setEditor(new CellEditor(number_data));
		columns.add(C7);
		ColumnConfig C8 = new ColumnConfig("skills", "技能", 200);
		TextField<String> text3 = new TextField<String>();
		C8.setEditor(new CellEditor(text3));
		columns.add(C8);
		ColumnConfig C9 = new ColumnConfig("uploader", "上传人", 80);
		columns.add(C9);
		ColumnConfig C2 = new ColumnConfig("uploadDate", "上传日期", 100);
		C2.setDateTimeFormat(DateTimeFormat.getFormat("yyyy-MM-dd"));
		columns.add(C2);

		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGridPanel(getStore(), cm, true, true) {
			@SuppressWarnings("unchecked")
			public void addnewrecord() {
				if (treeDepId == null) {
					MessageBox.alert("警告", "请选择一个分部门后再添加新信息", null);
					return;
				}
				auditOperation();
			}

		};
		cbs.setSelectionMode(SelectionMode.SIMPLE);
		grid.getBg().addPlugin(cbs);
		grid.getBg().setSelectionModel(cbs);
		Tools.setResize(grid.getBg(), 0.80, 0.86);
		return grid;
	}

	int sync = 0;
	Listener<BaseEvent> defaultlistener;

	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}

		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						if (be.getType() == Events.OnClick) {
							if (be.getSource().equals(search)) {
								String sql = grid.getBg().getStore()
										.getStoreinfo().getSql();
								String where = "";
								if (position.getValue() != null) {
									where = where + " and position like '%25"
											+ position.getValue() + "%25'";
								}
								if (name.getValue() != null) {
									where = where + " and name like '%25"
											+ name.getValue() + "%25'";
								}
								if (education.getValue() != null) {
									where = where + " and education = '"
											+ education.getRawValue() + "'";
								}
								if (experience.getValue() != null) {
									where = where + " and experience = '"
											+ experience.getRawValue() + "'";
								}
								if (!salaryStart.getRawValue().equals("")
										|| !salaryEnd.getRawValue().equals("")) {
									if (!salaryStart.getRawValue().equals("")
											&& !salaryEnd.getRawValue().equals(
													"")) {
										where = where + " and salary between "
												+ salaryStart.getValue()
												+ " and "
												+ salaryEnd.getValue();
									} else if (!salaryStart.getRawValue()
											.equals("")) {
										where = where + " and salary >= "
												+ salaryStart.getValue();
									} else {
										where = where + " and salary <= "
												+ salaryEnd.getValue();
									}
								}
								if (skills.getValue() != null) {
									where = where + " and skills like '%25"
											+ skills.getValue() + "%25'";
								}
								if (resumeNo.getValue() != null) {
									where = where + " and resumeNo like '%25"
											+ resumeNo.getValue() + "%25'";
								}
								String sql2 = sql + where;
								grid.getBg().getStore().getStoreinfo().setSql(
										sql2);
								grid.getBg().getStore().reload();
								grid.getBg().getView().refresh(true);
								grid.getBg().getStore().getStoreinfo().setSql(
										sql);
							}

							if (be.getSource().equals(request)) {
								if (grid.getBg().getSelectionModel()
										.getSelectedItems().size() == 0) {
									MessageBox.alert("提示",
											"你没选择简历，请选择一个以上的简历再进行申请，谢谢", null);
									return;
								}

								if (recruitmentId == 0L) {
									final Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
										public void handleEvent(
												MessageBoxEvent ce) {
											Button btn = ce.getButtonClicked();
											if (btn.getText().equals("是")) {
												List<Long> list = new ArrayList<Long>();
												/*
												 * 循环执行得到选中的复选框的icode，并将所有选中的简历icode保存在考核页面中
												 * ，用于以后直接在考核页面中直接申请职位。
												 * 打开考核页面时默认显示的sql为 所有通过考核的人力申请表
												 */
												for (Object md : grid.getBg()
														.getSelectionModel()
														.getSelectedItems()) {
													int index = grid
															.getBg()
															.getStore()
															.indexOf(
																	(ModelData) md);
													long id = (Long) grid
															.getBg().getValue(
																	index,
																	"icode");
													list.add(id);
												}
												String sql = "select * from hr_recruitmentRequest where isThrough = 'true' and hirePeople is null order by requestDate asc";
												RecruitmentAudit audit = new RecruitmentAudit(
														sql);
												audit.setLibraryList(list);
												audit.complete();
												BaseTabPanel
														.getInstance()
														.addTab("选择申请职位", audit);
											}
										}
									};
									MessageBox.confirm("提示信息",
											"你申请的职位为空，你可以点击\'是\'选择职位,谢谢", l);
									return;
								} else {
									dialog.show();
									dialog
											.getButtonById(Dialog.CANCEL)
											.addSelectionListener(
													new SelectionListener<ButtonEvent>() {
														@Override
														public void componentSelected(
																ButtonEvent ce) {
															List<String> list = new ArrayList<String>();
															/*
															 * 循环得到选中的复选框，并拼成insert语句，最后通过rpc执行操作
															 */
															for (Object md : grid
																	.getBg()
																	.getSelectionModel()
																	.getSelectedItems()) {
																
																int index = grid
																		.getBg()
																		.getStore()
																		.indexOf(
																				(ModelData) md);
																long id = (Long) grid
																		.getBg()
																		.getValue(
																				index,
																				"icode");
																String sql = "insert into hr_positionRequest(recruitmentId,resumeLibraryId,requestDate) values("
																		+ recruitmentId
																		+ ","
																		+ id
																		+ ",getdate())";
																list.add(sql);
															}
															insertRequest(list);
															cbs.deselectAll();
															dialog.hide();
														}
													});
									
									dialog
									.getButtonById(Dialog.OK)
									.addSelectionListener(
											new SelectionListener<ButtonEvent>() {
												@Override
												public void componentSelected(
														ButtonEvent ce) {
													List<String> list = new ArrayList<String>();
													if (box
															.getRawValue().equals("")) {
														MessageBox.alert("提示", "请选择信息来源，如果不先的请请点击‘暂时不填写’按钮，谢谢", null);
														return;
													}
													String informationFrom = box
													.getRawValue();
													/*
													 * 循环得到选中的复选框，并拼成insert语句，最后通过rpc执行操作
													 */
													for (Object md : grid
															.getBg()
															.getSelectionModel()
															.getSelectedItems()) {
														int index = grid
																.getBg()
																.getStore()
																.indexOf(
																		(ModelData) md);
														long id = (Long) grid
																.getBg()
																.getValue(
																		index,
																		"icode");
														String sql = "insert into hr_positionRequest(recruitmentId,resumeLibraryId,requestDate,informationForm) values("
																+ recruitmentId
																+ ","
																+ id
																+ ",getdate(),'"
																+ informationFrom + "')";
														list.add(sql);
													}
													insertRequest(list);
													cbs.deselectAll();
													dialog.hide();
												}
											});
								}
							}
						}
					}
				} finally {
					sync--;
				}
			}
		};
		return defaultlistener;
	}

	/**
	 * 
	 * 得到最大的简历编号，再自增设置为新的简历的编号
	 */
	public void auditOperation() {
		String sql = "select isnull(max(resumeNo),0) as max from hr_resumeLibrary";
		final GreetingServiceAsync greetingService = GWT
				.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService.getDataSet(sql, new AsyncCallback<DataSet>() {
			@Override
			public void onFailure(Throwable caught) {
			}

			@Override
			public void onSuccess(DataSet result) {
				String max = result.getValue(0, "max");
				String numbers = getRequestNo(max, 1);
				HashMap hp = new HashMap();
				hp.put("depCode", treeDepId);
				hp.put("uploadDate", new Date());
				hp.put("uploader", Env.getEnvname());
				hp.put("resumeNo", numbers);
				grid.getBg().getStore().add(hp);

				swfu = new SignleFileUpload("*.doc;*.pdf;.docx", 1, 204800);
				swfu.setParent(store);
				swfu.setUrl("gwtbase/uploadFileServlet?table=hr_resumeLibrary&file=" + resumeLibrary + treeDepId + "&action=insert");
				swfu.showDialog();
			}
		});
	}

	/**
	 * @param max
	 *            从RPC返回的最大申请表编号
	 * @param 最大申请表要增加的数量
	 * @return 审核通过的申请表编号 通过得到最大的编号，进行一系列的算法处理，得到6位数以上的编号
	 */
	private String getRequestNo(String max, int incremental) {
		int maxValue = Integer.parseInt(max);
		maxValue = maxValue + incremental;
		String maxString = String.valueOf(maxValue);
		String numbers = null;
		switch (maxString.length()) {
		case 1:
			numbers = "00000" + maxString;
			break;
		case 2:
			numbers = "0000" + maxString;
			break;
		case 3:
			numbers = "000" + maxString;
			break;
		case 4:
			numbers = "00" + maxString;
			break;
		case 5:
			numbers = "0" + maxString;
			break;
		default:
			numbers = maxString;
		}
		return numbers;
	}

	/**
	 * @param lists
	 *            要执行的sql语句
	 * @return 执行成功与否 执行所有的insert语句，完全申请表的提交操作
	 */
	public boolean insertRequest(List<String> lists) {
		CommandSyncsql csql = new CommandSyncsql();// 执行sql命令
		for (String sql : lists) {
			csql.getV().add(sql);
		}
		if (csql.getV().size() <= 0) {
			return false;
		} else {
			CommandSyncContainer list = new CommandSyncContainer();// 可以添加的命令
			list.add(csql);

			GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
			greetingService.SendCommandSync(list,
					new AsyncCallback<CommandSyncReturnObject>() {
						@Override
						public void onFailure(Throwable caught) {
							MessageBox.alert("错误", "网络连接失败", null);
						}

						@Override
						public void onSuccess(CommandSyncReturnObject result) {
							if (result.isB()) {
								Info.display("提示信息", "职位申请成功");
							} else {
								MessageBox.alert("错误", "错误，错误代码"
										+ result.getMessage(), null);

							}
						}
					});
		}
		return true;
	}

	public Long getRecruitmentId() {
		return recruitmentId;
	}

	public void setRecruitmentId(Long recruitmentId) {
		this.recruitmentId = recruitmentId;
	}
}
